home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / editors / mutt / me2s_pl7.zoo / mu_edit2 / util / tobase.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-05  |  631 b   |  34 lines

  1. static char rcsid[] = "$Id: tobase.c,v 1.1 1992/09/06 19:31:32 mike Exp $";
  2.  
  3. /* $Log: tobase.c,v $
  4.  * Revision 1.1  1992/09/06  19:31:32  mike
  5.  * Initial revision
  6.  *
  7.  */
  8.  
  9. /* tobase(x,base): convert x to base
  10.     see also todec()
  11.     Craig Durland    Public Domain
  12. */
  13.  
  14. #define TRUE 1
  15. #define FALSE 0
  16.  
  17. char *tobase(x,base) long x; int base;
  18. {
  19.   static char str[40];
  20.   char *ptr = &str[39];
  21.   int minus = FALSE, z;
  22.  
  23.   *ptr = '\0';
  24.   if (x < 0) { minus = TRUE; x = -x; }
  25.   do
  26.   {
  27.     if ((z = x % base)>9) z += 7;
  28.     *--ptr = z +'0';
  29.     x /= base;
  30.   } while (x>0);
  31.   if (minus) *--ptr = '-';
  32.   return(ptr);
  33. }
  34.